package io;

import java.io.*;

public class FileWrite {
	
	private static PrintWriter writer = null;
	
	public static void init(String file) {
		try {
			FileOutputStream fstream = new FileOutputStream(file);
			OutputStreamWriter out = new OutputStreamWriter(fstream, "UTF-8");
			writer = new PrintWriter(out, true);
			writer.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
		} catch (IOException e) {;}
	}

	public static void println(String s) {
		if (writer != null && s != null) {
			s = s.replaceAll("&", "&amp;");
			s = s.replaceAll(" > ", "&lt;");
			s = s.replaceAll(" < ", "&gt;");
			writer.println(s);
		}
	}
	
	public static void close() {
		if (writer != null)
			writer.close();
	}
	
	public static void main(String[] args) {
		String s = "<Test> < & > </Test>";
		FileWrite.init("/home/sylamer/Desktop/xquery.log");
		FileWrite.println(s);
		FileWrite.close();
	}
}
